<template>
    <micro-app
        v-if="microNode"
        name='customer'
        :url='linkurl'
        :data="microData"
        :baseurl='baseurl'
        :shadowDOM="roleInfo.shadow_dom==1"
        @datachange='handleDataChange'
    ></micro-app>
</template>

<script>
import microApp from '@micro-zoe/micro-app';
import dialogMicro from "./dialogMicro";
import { mapState } from 'vuex';

export default {
    data(){
        return {
            microNode: true,
            microData: {
                w7: {
                    getModuleInfo: () => {
                        return {
                            module_name: "module_name",
                            module_version: "module_version"
                        }
                    },
                    setStorage: ({key, value}) => {
                        return localStorage.setItem(key, value)
                    },
                    getStorage: (key) => {
                        return localStorage.getItem(key)
                    },
                    removeStorage: (key) => {
                        return localStorage.removeItem(key)
                    },
                    clearStorage: () => {
                        return localStorage.clear()
                    },
                    login: () => {
                        return new Promise((resolve,reject)=>{
                            resolve({code:(Math.random()+"").replace("0.","")})
                        })
                    },
                    dialogMicro: dialogMicro,
                    // 菜单收起展开
                    changeMenuCollapse: (boo) => {
                        this.$store.commit("setMenuCollapse",boo);
                    },
                    // jsticket获取
                    jsTicket(){
                        this.$message.warning("暂不支持");
                        return new Promise((resolve,reject)=>{
                            resolve({})
                        })
                    },
                    // 获取实名
                    realname(){
                        this.$message.warning("暂不支持");
                        return new Promise((resolve,reject)=>{
                            resolve({})
                        })
                    },
                    // 支付
                    pay: (ticket, callback, iframe)=>{
                        this.$message.warning("暂不支持");
                        return new Promise((resolve,reject)=>{
                            resolve({})
                        })
                    },
                    payment: (obj,callback, iframe)=>{
                        this.$message.warning("暂不支持");
                        return new Promise((resolve,reject)=>{
                            resolve({})
                        })
                    },
                    navigate: (obj)=>{
                        this.$message.warning("暂不支持");
                        return new Promise((resolve,reject)=>{
                            resolve({})
                        })
                    },
                    closeCard: (data)=>{
                        this.$message.warning("暂不支持");
                        return new Promise((resolve,reject)=>{
                            resolve({})
                        })
                    },
                }
            }
        }
    },
    props: ['linkurl','baseurl'],
    computed: {...mapState(['roleInfo'])},
    created(){
        console.log(this.linkurl)
    },
    methods: {
        handleDataChange(e){
            const path = e.detail.data.path;
            if(path){
                this.$router.push(path);
            }
        },
        changeRote(){
            let path = this.$route.fullPath.replace(this.baseurl,'');
            microApp.setData('customer', {
                type:'route',
                data: path,
                path: path,
                ...this.microData
            });
            // this.microNode = false;
            // this.$nextTick(()=>{
            //     this.microNode = true;
            // })
        },
    },
    watch: {
        $route(){this.changeRote()},
    }
}
</script>

<style>

</style>